package com.ax.base.drugstore.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ax.base.drugstore.domain.BasePersonnel;

@Mapper
public interface BasePersonnelMapper {
    int deleteByPrimaryKey(Long personnelId);

    int insert(BasePersonnel record);

    /**
	 * 药房人员保存(模块:药店人员)
	 * 
	 * @param BasePersonnel basePersonnel
	 *           
	 * @return SUCC
	 */
    @Insert("<script>"+
	 "insert into base_personnel (Personnel_ID, Personnel_Name, Drugstore_ID,"+ 
	      "Drugstore_Name, Type_Code, Type_Name,Person_ID, Empno, Sex, Birth,Entry_Time, Phone,"+
	      "Address, Remarks, create_date,update_date, Flag)"+
	      "values (#{personnelId}, #{personnelName}, #{drugstoreId},"+ 
	      "#{drugstoreName}, #{typeCode}, #{typeName},"+ 
	      "#{personId}, #{empno}, #{sex},"+ 
	      "#{birth}, #{entryTime}, #{phone},"+ 
	      "#{address}, #{remarks}, NOW(),"+ 
	      "NOW(), #{flag})"+
    	  "</script>")
    int insertSelective(BasePersonnel record);

    @Select("<script>" +
            "select"+
    		"base_personnel.Personnel_ID personnelId, base_personnel.Personnel_Name personnelName, base_personnel.Drugstore_ID drugstoreId,"+ 
    		"base_personnel.Drugstore_Name drugstoreName, base_personnel.Type_Code typeCode, base_personnel.Type_Name typeName,"+ 
    		"base_personnel.Person_ID personId, base_personnel.Empno empno, base_personnel.Sex sex, base_personnel.Birth birth,"+ 
    		"base_personnel.Entry_Time entryTime, base_personnel.Phone phone, base_personnel.Address address,"+
    		"base_personnel.Remarks remarks, base_personnel.create_date createDate, base_personnel.update_date updateDate,"+
    		"base_personnel.Flag flag"+
    		"from base_personnel"+
    		"<where>" + 
    	  	"<if test=\"personnelId != null\">"+ "and Personnel_ID = #{personnelId} " + "</if>" + 
    	  	"</where>"+
    		"</script>")
    BasePersonnel selectByPrimaryKey(Long personnelId);

    @Update("<script>"+
    		"update base_personnel"+
    	    "<set>"+
    		"<if test=\"personnelName != null and personnelName != ''\">"+ "Personnel_Name = #{personnelName}, " + "</if>" +
    		"<if test=\"drugstoreId != null\">"+ "Drugstore_ID = #{drugstoreId}, " + "</if>" +
    		"<if test=\"drugstoreName != null and drugstoreName != ''\">"+ "Drugstore_Name = #{drugstoreName}, " + "</if>" +
    		"<if test=\"typeCode != null and typeCode != ''\">"+ "Type_Code = #{typeCode}, " + "</if>" +
    		"<if test=\"typeName != null and typeName != ''\">"+ "Type_Name = #{typeName}, " + "</if>" +
    		"<if test=\"personId != null and personId != ''\">"+ "Person_ID = #{personId}, " + "</if>" +
    		"<if test=\"empno != null and empno != ''\">"+ "Empno = #{empno}, " + "</if>" +
    		"<if test=\"sex != null and sex != ''\">"+ "Sex = #{sex}, " + "</if>" +
    		"<if test=\"birth != null\">"+ "Birth = #{birth}, " + "</if>" +
    		"<if test=\"entryTime != null\">"+ "Entry_Time = #{entryTime}, " + "</if>" +
    		"<if test=\"phone != null and phone != ''\">"+ "Phone = #{phone}, " + "</if>" +
    		"<if test=\"address != null and address != ''\">"+ "Address = #{address}, " + "</if>" +
    		"<if test=\"remarks != null and remarks != ''\">"+ "Remarks = #{remarks}, " + "</if>" +
    		"<if test=\"createDate != null\">"+ "create_date = #{createDate}, " + "</if>" +
    		"update_date = NOW(),"+
    		"<if test=\"flag != null\">"+ "Flag = #{flag}, " + "</if>" +
    	    "</set>"+
    	    "where Personnel_ID = #{personnelId}"+
    		"</script>")
    int updateByPrimaryKeySelective(BasePersonnel record);

    int updateByPrimaryKey(BasePersonnel record);
    
    @Select("<script>" +
            "select"+
    		"base_personnel.Personnel_ID personnelId, base_personnel.Personnel_Name personnelName, base_personnel.Drugstore_ID drugstoreId,"+ 
    		"base_personnel.Drugstore_Name drugstoreName, base_personnel.Type_Code typeCode, base_personnel.Type_Name typeName,"+ 
    		"base_personnel.Person_ID personId, base_personnel.Empno empno, base_personnel.Sex sex, base_personnel.Birth birth,"+ 
    		"base_personnel.Entry_Time entryTime, base_personnel.Phone phone, base_personnel.Address address,"+
    		"base_personnel.Remarks remarks, base_personnel.create_date createDate, base_personnel.update_date updateDate,"+
    		"base_personnel.Flag flag,base_drugstore.Area_Name areaName,base_drugstore.Address drugAddress,"+
    		"from base_personnel"+
    		"left join base_drugstore on base_personnel.Drugstore_ID = base_drugstore.Drugstore_ID"+
    		"<where>" + 
    	  	"<if test=\"personnelId != null\">"+ "and base_personnel.Personnel_ID = #{personnelId} " + "</if>" + 
    	  	"<if test=\"drugstoreId != null\">"+ "and base_personnel.Drugstore_ID = #{drugstoreId} " + "</if>" +
    	  	"</where>"+
    	  	"<if test=\"offset != null and limit != null\">"+
    		"limit #{offset}, #{limit}" + 
    		"</if>"+
    		"</script>")
    List<BasePersonnel> queryDrugStoreManagerMapper(Map<String,Object> map);
    
    @Select("<script>" +
            "select"+
    		"count(0)"+
    		"from base_personnel"+
    		"left join base_drugstore on base_personnel.Drugstore_ID = base_drugstore.Drugstore_ID"+
    		"<where>" + 
    	  	"<if test=\"personnelId != null\">"+ "and base_personnel.Personnel_ID = #{personnelId} " + "</if>" + 
    	  	"</where>"+
    		"</script>")
    Integer count(Map<String,Object> map);
}